package org.smarthings.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.smarthings.Factory;

@Component(immediate = true)
@Reference(name = "FactoryConsumer", referenceInterface = Factory.class, policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, bind = "factoryActivated", unbind = "factoryDeactivated")
public class FactoryConsumerImpl {
	private static List<Factory> factories = new ArrayList<Factory>();

	protected void factoryActivated(Factory factory) {
		MessageBrokerImpl.getInstance().addFactory(factory);
		factories.add(factory);
	}

	protected void factoryDeactivated(Factory factory) {
		factories.remove(factory);
		MessageBrokerImpl.getInstance().removeFactory(factory);
	}

	public static List<Factory> getAllFactories() {
		return factories;
	}
}
